package jst.householdmanager.database;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class SQLiteDataSource {

	// Database fields
	private static SQLiteDatabase database;
	private SQLiteHelper dbHelper;

	public SQLiteDataSource(Context context) {
		dbHelper = new SQLiteHelper(context);
	}

	public void open() throws SQLException {
		database = dbHelper.getWritableDatabase();
	}

	public void close() {
		dbHelper.close();
	}

	public static SQLiteDatabase getDatabase() {
		return database;
	}

	public SQLiteHelper getDbHelper() {
		return dbHelper;
	}

	public static Cursor queryDatabase(String sqlStmt, String[] whereArgs) {
		Cursor cursor = SQLiteDataSource.getDatabase().rawQuery(sqlStmt, whereArgs);
		cursor.moveToFirst();
		return cursor;
	}

	public static Cursor queryDatabase(String sqlStmt) {
		return queryDatabase(sqlStmt, null);
	}

}
